| Total Complexity | 1 |
| Total Lines | 21 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { Inject, Injectable } from '@nestjs/common'; |
||
| 4 | |||
| 5 | @Injectable() |
||
| 6 | export class TableCsvFactory { |
||
| 7 | constructor( |
||
| 8 | @Inject('ITranslator') |
||
| 9 | private translator: ITranslator |
||
| 10 | ) {} |
||
| 11 | |||
| 12 | public toCsv(table: Table): string { |
||
| 13 | const header = table.columns.map(column => |
||
| 14 | this.translator.translate(column.toString()) |
||
| 15 | ); |
||
| 16 | const rows = table.rows.map(row => |
||
| 17 | row |
||
| 18 | .map(cell => { |
||
| 19 | const text = cell.renderText(); |
||
| 20 | return `"${text}"`; // Use quotes to allow newlines |
||
| 21 | }) |
||
| 22 | .join(';') |
||
| 23 | ); |
||
| 24 | return [header.join(';'), ...rows].join('\n'); |
||
| 25 | } |
||
| 27 |